package com.ruiyun.ruinews.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.ruiyun.ruinews.R;
import com.ruiyun.ruinews.base.RuiApplication;

import java.util.List;

/**
 * Created by zouhui on 16/1/7.
 */
public class NewsAdapter extends FragmentPagerAdapter {
    private List<Fragment> data;
    private List<String> title;
    private Context context;

    public NewsAdapter(FragmentManager fm,List<Fragment> data,List<String> title) {
        super(fm);
        this.context = RuiApplication.context;
        this.data = data;
        this.title = title;
    }



    @Override
    public Fragment getItem(int position) {
        return data.get(position);
    }

    @Override
    public int getCount() {
        return title == null ? 0 : title.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return null;
    }

    public View getTab(int position){
        View view = LayoutInflater.from(context).inflate(R.layout.tab_main_tablayout,null);
        TextView textView = (TextView) view.findViewById(R.id.tv_main_tablayout_tab);
        textView.setText(title.get(position));
        return view;
    }
}
